package com.xunyu.shopping_manager_api.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import com.xunyu.shopping_manager_api.interceptor.CheckLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Autowired
    private CheckLoginInterceptor checkLoginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录检查拦截器
       registry.addInterceptor(checkLoginInterceptor)
               .addPathPatterns("/**")//拦截所有请求
               .excludePathPatterns("/admin/login");//排除登录请求
        //权限检查拦截器
        registry.addInterceptor(new SaInterceptor())
                .addPathPatterns("/**");//拦截所有的请求（都需要权限检查）
    }
}
